# -*- coding: utf-8 -*-

from hlm.node import *

from ip.trunner import NodeTRunner
from ip.peer_cluster import NodePeerCluster


class NodeHana(Node):
    """ NodeHana is a chip level simulation node for the implementation of the
    HANA core. It contains the following elements.

    1. A single instance of T-Runner.
    2. A single instance of Cluster level peer node. (Peer Cluster)
    """
    def initialize(self, params: ObjectDict) -> None:
        params.multiplexer: int
        params.peer_id_base: int
        params.num_of_peer_group: int
        params.num_of_peer: int
        params.softmem_size: int
        params.num_of_main_memory: int
        params.num_of_alu: int
        params.total_peers: int
        params.base_ptrs: 'List.int'

        # Initialize a T-Runner.
        self.node.trunner = self.node_create(
            NodeTRunner,
            {'num_of_main_memory': params.num_of_main_memory,
             'multiplexer': params.multiplexer})
        # Initialize a execution unit, here is a cluster level node.
        self.node.cluster = self.node_create(
            NodePeerCluster,
            {'peer_id_base': params.peer_id_base,
             'num_of_peer_group': params.num_of_peer_group,
             'num_of_peer': params.num_of_peer,
             'softmem_size': params.softmem_size,
             'num_of_main_memory': params.num_of_main_memory,
             'num_of_alu': params.num_of_alu,
             'multiplexer': params.multiplexer,
             'total_peers': params.total_peers,
             'base_ptrs': params.base_ptrs})

        # Expose the ports of the chip.
        self.port.top_receiver = self.port_bypass(self.node.trunner.port.nano_op_receiver)
        self.port.eop_receiver = self.port_bypass(self.node.cluster.port.nano_op_receiver)
        # Expose the memory receivers.
        self.port.memory_receivers = self.port_bypass(self.node.cluster.port.memory_receivers)
        self.port.memory_senders = self.port_bypass(self.node.cluster.port.memory_senders)
        # Expose the T-Runner senders.
        self.port.memory_requester = self.port_bypass(self.node.trunner.port.memory_ports)
        # Bypass the halt signal.
        self.port.halt = self.port_bypass(self.node.cluster.port.halt)
